/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import { message } from "antd";
import {
  getScanningList,
  getSingleList,
  getWorkList,
} from "@/services/scanning";

const noop = () => {};
export default {
  namespace: "scanning",

  state: {
    scanning:{
      list: [],
      pagination: null,
      formValues:null,
    },
    singleNumber:{
      list: [],
      pagination: null,
    },
    workNumber:{
      list: [],
      pagination: null,
      formValues:null,
    },

  },

  effects: {
    // 扫描记录统计
    * getScanningList({ payload }, { call, put }) {
      const response = yield call(getScanningList, payload);
      if (!response) return;
      const { code, data, msg } = response;
      const { ret, cnt, page, pageSize } = data;
      if (code == 0 && data) {
        yield put({
          type: "save",
          payload: {
            scanning:{
              list: ret,
              pagination: {
                total:cnt,
                pageSize,
                current: page,
                sizeType:false,
              },
              formValues:payload,
            },
          },
        });
      } else {
        yield put({
          type: "save",
          payload: {
            scanning:{
              list: ret,
              pagination: {
                total:cnt,
                pageSize,
                current: page,
                sizeType:false,
              },
              formValues:payload,
            },
          },
        });
        message.error(msg);
      }
    },
    // 扫描记录查询单号
    * getSingleList({ payload }, { call, put }) {
      const response = yield call(getSingleList, payload);
      if (!response) return;
      const { code, data, msg } = response;
      if (code == 0 && data) {
        yield put({
          type: "save",
          payload: {
            singleNumber:{
              list: data,
            },
          },
        });
      } else {
        yield put({
          type: "save",
          payload: {
            singleNumber:{
              list: [],
            },
          },
        });
        message.error(msg);
      }
    },
    // 扫描记录查询业务员
    * getWorkList({ payload }, { call, put }) {
      const response = yield call(getWorkList, payload);
      if (!response) return;
      const { code, data, msg } = response;
      const { ret, cnt, page=1, pageSize } = data;
      if (code == 0 && data) {
        yield put({
          type: "save",
          payload: {
            workNumber:{
              list: ret,
              pagination: {
                total:cnt,
                pageSize,
                current: page,
                sizeType:false,
              },
              formValues:payload,
            },
          },
        });
      } else {
        yield put({
          type: "save",
          payload: {
            workNumber:{
              list: ret,
              pagination: {
                total:cnt,
                pageSize,
                current: page,
                sizeType:false,
              },
              formValues:payload,
            },
          },
        });
        message.error(msg);
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
